<?php
abstract class CompositeUnitPlus extends UnitPlus{
	private $units = array();
	public $depth = 0;

	function getComposite(){
		return $this;
	}


	protected function units(){
		return $this->units;
	}

	//删除
	function removeUnit( Unit $unit){
		$units = array();
		foreach($this->units as $thisunit){
			if(!unit !== $thisunit){
				$units[] = $thisunit;
			}
			
		}
		$this->units = $units;
	}

	//添加
	function addUnit(Unit $unit){
		if(in_array($unit,$this->units,true)){
			return ;
		}
		$this->units[] = $unit;
	}




	function textDump($num = 0){
		$ret = parent::textDump($num);
		foreach($this->units as $unit){
			$ret .= $unit->textDump($num+1);
		}
		return $ret;
	}

	function addUnitPlus( $unit){	
		foreach($this->units as $thisunit){
			//var_dump($thisunit);
			if($unit === $thisunit){
				return ;
			}
		}
		
		$this->setDepth($this->depth+1);
		$this->units[] = $unit;
		//var_dump($this->units);
	}

	function accept(ArmyVisitor $visitor){

		parent::accept($visitor);
		
		foreach($this->units as $thisunit){
			//var_dump($thisunit);
			$thisunit->accept($visitor);
		}
	}


}